Desktop/Copy of GPS_TRACE/SRC/main.c

Go to the documentation of this file.
00001 /*********************************************
00002 * Chip type           : ATmega16
00003 * Clock frequency     : 4,000000 MHz
00004 Poort1 --> DCE Modem (poort bij open gedeelte)
00005 Poort0 --> Computer  (poort bij MAX232 chip)
00006 *********************************************/
00007 #include <avr/io.h>
00008 #include <avr/interrupt.h>
00009 #include <avr/signal.h>
00010 #include <inttypes.h>
00011 #include "lcd.h"
00012 #include "led.h"
00013 #include "RS232.h"
00014 #include "init.h"
00015 #include "status.h"
00016 #include "NMEA0183Parser.h"
00017 #include "GSMParser.h"
00018 
00019 
00020 typedef volatile unsigned char BYTE; //definitie type BYTE
00021 typedef volatile unsigned int WORD; //definitie type WORD
00023 // Defines
00025 #define STOP_TIMER0    TCCR0 &= 0xF8
00026 #define START_TIMER0   TCCR0 |= 0x05
00027 #define STOP_TIMER1    TCCR2 &= 0xF8
00028 #define START_TIMER1   TCCR2 |= 0x05
00029 
00030 
00032 // Global Varibles
00034 WORD Ticks256; 
00035 WORD Ticks512;
00036 
00037 int bufferwritepos = 0; // de schrijf positie van de buffer (GPS)
00038 int bufferreadpos = 0; //de lees positie van de buffer (GPS)
00039 int bufferwriteposGSM = 0; // de schrijf positie van de buffer (GSM)
00040 int bufferreadposGSM = 0; //de lees positie van de buffer (GSM)
00041 char lexeme[100]; //de buffer van de GPS
00042 char GSMlexeme[60]; //de buffer van de GSM 
00043 
00049 SIGNAL(SIG_OVERFLOW0)
00050 //ISR(TIMER0_OVF_vect)
00051 {
00052  // 256 ticks have gone by
00053  Ticks256++;
00054  // If you do the math you'll find that if the interrupt goes off 275 times, a minute has passed
00055  if (Ticks256 == 200)
00056  {
00057   led_toggle_green();
00058   Ticks256 = 0;
00059  }
00060 }
00061 
00062 
00068 SIGNAL(SIG_OVERFLOW2)
00069 //ISR(TIMER0_OVF_vect)
00070 {
00071  // 256 ticks have gone by
00072  Ticks512++;
00073 
00074 
00075  // If you do the math you'll find that if the interrupt goes off 275 times, a minute has passed
00076  if (Ticks512 == 200)
00077  {
00078   showFixstate();
00079   led_toggle_red();
00080   Ticks512 = 0;
00081  }
00082 }
00083 
00089 void ConfigureDevice ()
00090 {
00091 
00092 
00093 
00094 cli(); // disable interrupts just in case
00095         Ticks256 = 0; 
00096         Ticks512 = 0;
00097  
00098  // configure PORTB... and other settings
00099 
00100  TCNT0 = 0x00;   // clear Timer/Counter 0
00101  TCNT2 = 0x00;   // clear Timer/Counter 2
00102  START_TIMER0;
00103  START_TIMER1;
00104  
00105  // enable interrupts on timer 0 overflow
00106  TIMSK  |= _BV(TOIE0);
00107  // enable interrupts on timer 2 overflow
00108   TIMSK  |= _BV(TOIE2);
00109 
00110 
00111                 
00112  sei(); // enable interrupts 
00113 }
00114 
00115 
00117 
00122 SIGNAL (SIG_USART0_RECV) { // USART RX interrupt
00123    unsigned char c;
00124    c = UDR0;
00125   if (bufferwriteposGSM==60)
00126    {
00127         bufferwriteposGSM=0;
00128         GSMlexeme[bufferwriteposGSM]=c;
00129         bufferwriteposGSM ++;
00130    }
00131    else
00132    {
00133                 GSMlexeme[bufferwriteposGSM]=c;
00134                 bufferwriteposGSM++;
00135    }
00136 
00137    }
00139 
00141 //
00147 SIGNAL (SIG_USART1_RECV) 
00148 { 
00149    unsigned char c;
00150    c = UDR1;
00151    if (bufferwritepos==100)
00152    {
00153         bufferwritepos=0;
00154         lexeme[bufferwritepos]=c;
00155         bufferwritepos++;
00156    }
00157    else
00158    {
00159                 lexeme[bufferwritepos]=c;
00160                 bufferwritepos++;
00161    }
00162 }
00164 //
00171 int main(void) {
00172         //initialisatie leds
00173         led_init();
00174         
00175         //initialisatie timers
00176         ConfigureDevice ();
00177 
00178         
00179         //lexeme vullen met ~ teken om producer/consumer probleem tegen te gaan
00180         int i = 0;
00181         for (; i<99; i++)
00182         {//lexeme vullen met het teken ~
00183                 lexeme[i]='~';
00184         }
00185 
00186         //GSMlexeme om dezelfde rede vullen
00187         int a = 0;
00188         for (; a<59; a++)
00189         {
00190                 GSMlexeme[a]='~';
00191         } 
00192         
00193         //initialisatie van LCD disply
00194         InitLCDText();
00195         
00196         //rode led aan (init voltooid tot zover)
00197         led_red_on();
00198 
00199         //initialisatie UARTS
00200         InitUarts();
00201 
00202         //initialisatie GSM module              
00203         initGSM();
00204         
00205         //sendTestSMS();
00206         
00207         //Initialisatie van NMEA0183 Parser
00208         initNMEA();
00209 
00210         //Initialisatie van GSP Parser
00211         InitGSMParser();
00212         
00213         //geel ledje aan (init voltooid)
00214         led_yellow_on();
00215 
00216       while (1) {
00217 
00218               //Buffer van NMEA parser voeden indien lees en schrijf positie
00219               //niet gelijk zijn, en de entry nog niet is gelezen.      
00220               if (lexeme[bufferreadpos]!='~'&&bufferreadpos!=bufferwritepos)
00221                 {
00222                         // uart0_putc(lexeme[bufferreadpos]);
00223                          NMEAFeedBuffer (lexeme[bufferreadpos]);
00224                          lexeme[bufferreadpos]='~';
00225                          bufferreadpos++;
00226                          if (bufferreadpos==100){
00227                                 bufferreadpos=0;}
00228                 }  
00229                 //buffer van de GSM parser voeden indien less en schrijf positie
00230                 //niet gelijk zijn en de entry nog niet is gelezen
00231                 if (GSMlexeme[bufferreadposGSM]!='~'&&bufferreadposGSM!=bufferwriteposGSM)
00232                 {
00233                         GSMFeedBuffer (GSMlexeme[bufferreadposGSM]);
00234                         GSMlexeme[bufferreadposGSM]='~';
00235                         bufferreadposGSM++;
00236                         if (bufferreadposGSM==60)
00237                         {
00238                                 bufferreadposGSM=0;
00239                         }
00240                 }
00241 
00242   }
00243  return 0; 
00244 }

Generated on Fri Aug 17 13:50:54 2007 for GPS TRACE by  doxygen 1.5.3